#pragma once
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <assert.h>
#include <stdbool.h>
typedef int SlDataType;

typedef struct Stack
{
	SlDataType* a;
	int top;
	int capacity;
}ST;

void STInit(ST* pst);
void STDestory(ST* pst);
void STPush(ST* pst, SlDataType x);
void STPop(ST* pst);
SlDataType STTop(ST* pst);
bool STEmpty(ST* pst);
int STSize(ST* pst);
void STInit(ST* pst)
{
	assert(pst);
	pst->a = NULL;
	pst->top = 0;
	pst->capacity = 0;
}

void STDestory(ST* pst)
{
	assert(pst);
	free(pst->a);
	pst->a = NULL;
	pst->capacity = 0;
	pst->top = 0;
}

void STPush(ST* pst, SlDataType x)
{
	assert(pst);
	if (pst->top == pst->capacity)
	{
		if (pst->capacity == 0)
			pst->capacity = 4;
		else
			pst->capacity *= 2;
		SlDataType* tmp = (SlDataType*)realloc(pst->a, pst->capacity * sizeof(SlDataType));
		pst->a = tmp;
	}
	pst->a[pst->top] = x;
	(pst->top)++;
}

void STPop(ST* pst)
{
	assert(pst);
	assert(!STEmpty(pst));

	pst->top--;
}

SlDataType STTop(ST* pst)
{
	assert(pst);
	assert(!STEmpty(pst));
	return pst->a[pst->top - 1];
}

bool STEmpty(ST* pst)
{
	assert(pst);
	if (pst->top == 0)
		return true;
	return false;
}

int STSize(ST* pst)
{
	assert(pst);
	return pst->top;
}
